package org.my.spring.agent.app.controller;

import com.alibaba.fastjson2.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.my.spring.agent.app.service.AgentRouterService;
import org.my.spring.agent.common.domain.Result;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 大模型对话接口
 */
@RestController
@RequiredArgsConstructor
@CrossOrigin
@RequestMapping("/api/agent")
@Slf4j
public class AgentApiController {
    private final AgentRouterService agentRouterService;

    /**
     * 对话接口
     *
     * @param jsonObject 用户输入参数
     * @return 模型回复
     */
    @PostMapping("/chat")
    public Result<?> chat(@RequestBody JSONObject jsonObject) {
        if (ObjectUtils.isEmpty(jsonObject)) {
            return Result.error("参数错误");
        }
        return agentRouterService.routeAndExecute(jsonObject);
    }
}

